package com.example.myqq;

import java.util.Iterator;
import java.util.List;

import com.easemob.EMEventListener;
import com.easemob.EMNotifierEvent;
import com.easemob.chat.EMChat;
import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMMessage;
import com.easemob.util.EMLog;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;
import android.widget.Toast;

public class MyApplicaton extends Application {
	public static Context appContext;
//	private  EMEventListener eventListener;
	@Override
	public void onCreate() {
		super.onCreate();
		appContext = this;

		// 初始化环信聊天SDK
		Log.d("EMChat Demo", "initialize EMChat SDK");
		EMChat.getInstance().setDebugMode(true);
		EMChat.getInstance().init(appContext);
	}

	/**
	 * check the application process name if process name is not qualified, then
	 * we think it is a service process and we will not init SDK
	 * 
	 * @param pID
	 * @return
	 */
	private String getAppName(int pID) {
		String processName = null;
		ActivityManager am = (ActivityManager)
				getSystemService(Context.ACTIVITY_SERVICE);
		List l = am.getRunningAppProcesses();
		Iterator i = l.iterator();
		PackageManager pm = this.getPackageManager();
		while (i.hasNext()) {
			ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i
					.next());
			try {
				if (info.pid == pID) {
					CharSequence c = pm.getApplicationLabel(pm
							.getApplicationInfo(info.processName,
									PackageManager.GET_META_DATA));
					processName = info.processName;
					return processName;
				}
			} catch (Exception e) {
				// Log.d("Process", "Error>> :"+ e.toString());
			}
		}
		return processName;
	}
	/*
	 * 注册消息监听
	 * */
//	private void initLis(){
//		 eventListener = new EMEventListener() {
//            @Override
//            public void onEvent(EMNotifierEvent event) {
//            	
//                switch (event.getEvent()) {
//                case EventNewMessage:
//                {
//                	 EMMessage message = (EMMessage)event.getData();
//                	 Log.d("main",message.getBody().toString());
//                    break;
//                }
//                case EventNewCMDMessage:
//                {
//                    break;
//                }
//                // add other events in case you are interested in
//                default:
//                    break;
//                }
//                
//            }
//        };
//        EMChatManager.getInstance().registerEventListener(eventListener);
//	}
}
